package com.duk.main;
import java.util.ArrayList;
import java.util.List;

import android.app.ActivityGroup;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.rss_reader.data.News_back;
import com.rss_reader.data.StaticURL;
public class MoreActivity extends ActivityGroup implements OnItemClickListener {   
    private ListView mListView;   
    News_back localNews_back;
    private List<String> items;      
    @Override  
    public void onCreate(Bundle savedInstanceStated) {   
        super.onCreate(savedInstanceStated);   
        setContentView(R.layout.more_view);   
        mListView = (ListView) findViewById(R.id.list_view); 
        mListView.setOnItemClickListener(this);
        fillArray();   
        mListView.setAdapter(new CustomListAdapter(this));   
    }   
       
    private void fillArray() {
    	
    	items = new ArrayList<String>();      
        items.add("汽车");   
        items.add("房产");   
        items.add("关于");   
        items.add("版权"); 
        
       
    }   
    class CustomListAdapter extends BaseAdapter {   
        private LayoutInflater mInflater;   
        private Context mContext = null;   
        public CustomListAdapter(Context context) {   
            mContext = context;   
            mInflater = LayoutInflater.from(mContext);   
        }   
        public Object getItem(int arg0) {   
            // TODO Auto-generated method stub   
            return items.get(arg0);   
        }   
        public long getItemId(int position) {   
            // TODO Auto-generated method stub   
            return position;   
        }   
        public int getCount() {   
            // TODO Auto-generated method stub   
            return items.size();   
        }   
        public View getView(int position, View convertView, android.view.ViewGroup parent) {   
            final ImageView indexImage;   
            final TextView indexText;   
            if (convertView == null) {   
                // 和more_item脚本关联   
                convertView = mInflater.inflate(R.layout.more_item, null);   
            }   
            indexImage = (ImageView) convertView.findViewById(R.id.index_image);   
            indexText = (TextView) convertView.findViewById(R.id.index_text);   
            // 设置item中indexText的文本   
            indexText.setText(items.get(position).toString());                  
            // 设置item中ImageView的图片   
            switch(position) {
            	case 0:
            		indexImage.setBackgroundResource(R.drawable.car);
            		break;
            	case 1:
            		indexImage.setBackgroundResource(R.drawable.house);
            		break;
            	case 2:
            		indexImage.setBackgroundResource(R.drawable.about);
            		break;
            	case 3:
            		indexImage.setBackgroundResource(R.drawable.copyrights);
            		break;
            	default :
            		indexImage.setBackgroundResource(R.drawable.icon);
            		break;
            }
           
            return convertView;   
        }   
    }
    public void onItemClick(AdapterView parent, View v, int position, long id)
    {
    	Intent itemintent = new Intent(this,ShowHtml.class);         
    	 Bundle b = new Bundle();
    	switch(position) {
    		case 0:
    			b.putString("CopyrightUrl", StaticURL.ABOUT);
    			itemintent.putExtra("android.intent.extra.rssItem", b);
    			break;
    		case 1:
    			
    			b.putString("CopyrightUrl", StaticURL.ABOUT);
    			itemintent.putExtra("android.intent.extra.rssItem", b);
    			break;
    		case 2:
    			b.putString("CopyrightUrl", StaticURL.ABOUT);
    	    	itemintent.putExtra("android.intent.extra.rssItem", b);
    			break;
    		case 3:
    			b.putString("CopyrightUrl", StaticURL.COPYRIGHT);
    	    	itemintent.putExtra("android.intent.extra.rssItem", b);
    			break;
    	}
    	 
         startActivityForResult(itemintent, 0);
    	
    }
    private Dialog ExitDialog(Context context) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setIcon(R.drawable.icon);
		builder.setTitle("生活新报提示");
		builder.setMessage("确定退出么?");
		builder.setPositiveButton("确定",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						finish();
					}
				});
		builder.setNegativeButton("取消",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {

					}
				});
		return builder.create();
	}
   
    @Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			ExitDialog(MoreActivity.this).show();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
   
} 